package com.feib.soeasy.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * @title (#)UserLoginControl.java<br>
 * @description 使用者登入資料<br>
 * @author Anson Tsai<br>
 * @version 1.0.0 2010/11/25
 * @copyright Far Eastern International Bank Copyright (c) 2010<br>
 * @2010/12/5 create by Anson Tsai<br>
 */
@Entity
@Table(name = "USER_LOGIN_CONTROL", uniqueConstraints = { @UniqueConstraint(columnNames = { "USER_PK" }) })
public class UserLoginControl {

    /**
     * <code>serialVersionUID</code> 的註解
     */
    private static final long serialVersionUID = 1L;

    /**
     * PK in Table
     */
    private Long userLoginConPk;
    
    /**
     * 登入帳號
     */
    private User user;

    /**
     * 登入Session ID
     */
    private String sessionId;

    /**
     * 最近一次登入時間
     */
    private Date loginTime;

    /**
     * 登入位址
     */
    private String loginLocale;

    /**
     * 是否啟用 <li>true: 啟用</li> <li>false: 停用</li>
     */
    private Boolean actived;
    
    /**
     * 最近異動時間
     */
    private Date activityTime;

    /**
     * @return 傳回 userLoginConPk。
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "USER_LOGIN_CON_PK", nullable = false)
    public Long getUserLoginConPk() {
        return userLoginConPk;
    }

    /**
     * @param userLoginConPk 要設定的 userLoginConPk。
     */
    public void setUserLoginConPk(Long userLoginConPk) {
        this.userLoginConPk = userLoginConPk;
    }

    
    /**
     * @return the user
     */
    @OneToOne
    @JoinColumn(name="USER_PK", nullable=false)
    public User getUser() {
        return user;
    }

    
    /**
     * @param user the user to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * @return 傳回 sessionId。
     */
    @Column(name = "SESSION_ID", nullable = false, length = 100)
    public String getSessionId() {
        return sessionId;
    }

    /**
     * @param sessionId 要設定的 sessionId。
     */
    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    /**
     * @return 傳回 loginTime。
     */
    @Column(name = "LOGIN_TIME")
    public Date getLoginTime() {
        return loginTime;
    }

    /**
     * @param loginTime 要設定的 loginTime。
     */
    public void setLoginTime(Date loginTime) {
        this.loginTime = loginTime;
    }

    /**
     * @return 傳回 loginLocale。
     */
    @Column(name = "LOGIN_LOCALE", nullable = true, length = 50)
    public String getLoginLocale() {
        return loginLocale;
    }

    /**
     * @param loginLocale 要設定的 loginLocale。
     */
    public void setLoginLocale(String loginLocale) {
        this.loginLocale = loginLocale;
    }

    /**
     * @return 傳回 actived。
     */
    @Column(name = "IS_ACTIVED")
    public Boolean getActived() {
        return actived;
    }

    /**
     * @param actived 要設定的 actived。
     */
    public void setActived(Boolean actived) {
        this.actived = actived;
    }

    
    /**
     * @return the activityTime
     */
    @Column(name = "ACTIVITY_TIME")
    public Date getActivityTime() {
        return activityTime;
    }

    
    /**
     * @param activityTime the activityTime to set
     */
    public void setActivityTime(Date activityTime) {
        this.activityTime = activityTime;
    }

    @Override
    public boolean equals(final Object other) {
        if (this == other)
            return true;
        if (!(other instanceof UserLoginControl))
            return false;
        UserLoginControl castOther = (UserLoginControl) other;
        return new EqualsBuilder().append(userLoginConPk, castOther.userLoginConPk).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(userLoginConPk).toHashCode();
    }
}
